package com.suos.conf;


import com.suos.core.SugarExecutor;
import com.suos.core.SugarOshi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.annotation.Resource;
import java.util.concurrent.Executor;

/**
 * des : 注入配置
 *
 * @author : MisShi
 * @date : 2021-08-24 11:39:07
 */
@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties(SuOsProperties.class)
public class SuOsAutoConfiguration{


    @Resource(type = SuOsProperties.class)
    public SuOsProperties suOsProperties;

    @Bean
    public SugarOshi sugarOshi() {
        return new SugarOshi(suOsProperties);
    }

    @Bean
    @ConditionalOnExpression("${sugar.oshi.distributed:false}")
    public SugarExecutor sugarExecutor() {
        return new SugarExecutor(suOsProperties);
    }

}
